package expandingproject;

import java.util.Scanner;

/**
 *
 * @author Inderpreet
 */
public class Calculator {

    public String getUserInput() {
        Scanner keyb = new Scanner(System.in);
        System.out.println("What would you like to do?");
        System.out.println("1) Add");
        System.out.println("2) Subtract");
        System.out.println("3) Multiply");
        System.out.println("4) Divide");
        String userOption = keyb.nextLine();
        if (userOption.equalsIgnoreCase("1") || userOption.equalsIgnoreCase("Add")) {
            return "Add";
        } else if (userOption.equalsIgnoreCase("2") || userOption.equalsIgnoreCase("Subtract")) {
            return "Subtract";
        } else if (userOption.equalsIgnoreCase("3") || userOption.equalsIgnoreCase("Multiply")) {
            return "Multiply";
        } else if (userOption.equalsIgnoreCase("4") || userOption.equalsIgnoreCase("Divide")) {
            return "Divide";
        }
        return "";
    }

    public void addNumbers() {
        Scanner keyb = new Scanner(System.in);
        String playAgain = "";
        while (!playAgain.equalsIgnoreCase("N")) {
            try {
                System.out.println("What is the first number to add?");
                int number1 = Integer.parseInt(keyb.nextLine());
                System.out.println("What is the second number to add?");
                int number2 = Integer.parseInt(keyb.nextLine());
                System.out.println(number1 + "+" + number2 + "= " + (number1 + number2));
                System.out.println("Continue? (Y/N)");
                playAgain = keyb.nextLine();
            } catch (Exception a) {
                System.out.println(a + "Not a number!");
            }
        }
    }

    public void subtractNumbers() {
        Scanner keyb = new Scanner(System.in);
        String playAgain = "";
        while (!playAgain.equalsIgnoreCase("N")) {
            try {
                System.out.println("What is the first number to subtract?");
                int number1 = Integer.parseInt(keyb.nextLine());
                System.out.println("What is the second number to subtract?");
                int number2 = Integer.parseInt(keyb.nextLine());
                System.out.println(number1 + "-" + number2 + "= " + (number1 - number2));
                System.out.println("Continue? (Y/N)");
                playAgain = keyb.nextLine();
            } catch (Exception a) {
                System.out.println(a + "Not a number!");
            }
        }
    }

    public void multiplyNumbers() {
        Scanner keyb = new Scanner(System.in);
        String playAgain = "";
        while (!playAgain.equalsIgnoreCase("N")) {
            try {
                System.out.println("What is the first number to multiply?");
                int number1 = Integer.parseInt(keyb.nextLine());
                System.out.println("What is the second number to multiply?");
                int number2 = Integer.parseInt(keyb.nextLine());
                System.out.println(number1 + "*" + number2 + "= " + (number1 * number2));
                System.out.println("Continue? (Y/N)");
                playAgain = keyb.nextLine();
            } catch (Exception a) {
                System.out.println(a + "Not a number!");
            }
        }
    }

    public void divideNumbers() {
        Scanner keyb = new Scanner(System.in);
        String playAgain = "";
        while (!playAgain.equalsIgnoreCase("N")) {
            try {
                System.out.println("What is the first number?");
                int number1 = Integer.parseInt(keyb.nextLine());
                System.out.println("What is the number to be divided by?");
                int number2 = Integer.parseInt(keyb.nextLine());
                System.out.println(number1 + "/" + number2 + "= " + (number1 / number2));
                System.out.println("Remainder: " + (number1 % number2));
                System.out.println("Continue? (Y/N)");
                playAgain = keyb.nextLine();
            } catch (Exception a) {
                System.out.println(a + "Not a number!");
            }
        }
    }
}
